package com.bdqn.zhang.action;

import com.alibaba.fastjson.JSON;
import com.bdqn.zhang.entity.RealEstate;
import com.bdqn.zhang.entity.Users;
import com.bdqn.zhang.service.RealEstateService;
import com.bdqn.zhang.service.UsersService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import java.util.List;

/**
 * Created by 任 on 2019/4/12.
 */
public class HousAction extends ActionSupport implements ModelDriven<RealEstate>{
    private RealEstate realEstate=new RealEstate();
    private Users users=new Users();
    @Override
    public RealEstate getModel() {  return realEstate;}

    private RealEstateService realEstateService;
    private UsersService usersService;
    private String result;
    public Integer page;
    public Integer limit;

    public RealEstate getRealEstate() {
        return realEstate;
    }

    public void setRealEstate(RealEstate realEstate) {
        this.realEstate = realEstate;
    }

    public Users getUsers() {
        return users;
    }

    public void setUsers(Users users) {
        this.users = users;
    }

    public RealEstateService getRealEstateService() {
        return realEstateService;
    }

    public void setRealEstateService(RealEstateService realEstateService) {
        this.realEstateService = realEstateService;
    }

    public UsersService getUsersService() {
        return usersService;
    }

    public void setUsersService(UsersService usersService) {
        this.usersService = usersService;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getLimit() {
        return limit;
    }

    public void setLimit(Integer limit) {
        this.limit = limit;
    }


    public String house() throws Exception {
        System.out.println("index");
        return SUCCESS;
    }

    /**
     * 查詢
     * @return
     * @throws Exception
     */
    public String realEstatelist() throws Exception {
        List<RealEstate> realEstatelist = realEstateService.findAllRealEstate(page,limit);
        result = JSON.toJSONStringWithDateFormat(realEstatelist, "yyyy-MM-dd");
        return SUCCESS;
    }

    /***
     * 修改
     * @return
     * @throws Exception
     */
    public String updatRealEstate() throws Exception {
        if( realEstateService.updRealEstate(realEstate)==true){
            result="true";
        }else {
            result = "false";
        }
        return  SUCCESS;
    }

    /***
     * 刪除
     * @return
     * @throws Exception
     */
    public String delRealEstate() throws Exception {

        if( realEstateService.delRealEstate(realEstate)==true){
            result="true";
        }else {
            result = "false";
        }
        return  SUCCESS;
    }

    /**
     * 添加
     * @return
     * @throws Exception
     */
    public String addRealEstate() throws Exception {

        if( realEstateService.addRealEstate(realEstate)==true){
            result="true";
        }else {
            result = "false";
        }
        return  SUCCESS;
    }
}
